package org.android.ui;


import org.example.xlibs.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class XToastUtil {
	
	private static Toast result = null;
	
	/**
	 * 自定义Toast方法
	 * @param content     上下文
	 * @param msg         所显示的信息
	 * @param duration    Toast.LENGTH_SHORT|Toast.LENGTH_LONG
	 * 
	 * 注：custom_toast布局XML文件控制显示的形状（shape）
	 */
	public static void showToastCustom(Context content,String msg,int duration){
		if(result  != null){ 
	    	result.cancel();
	    }
	    result = new Toast(content);
        LayoutInflater inflate = (LayoutInflater)content.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflate.inflate(R.layout.custom_toast, null);
        TextView tv = (TextView)v.findViewById(R.id.tv_toast);
        result.setView(v);
        tv.setText(msg);
        result.setDuration(duration);
//        result.setGravity(Gravity.TOP, 30, 30);
        result.show();
	}
}
